package Testdmo5;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:周次煜
 * Date: 2024-03-27
 * Time：15:54
 */
//public class J3_27 {
//}
//
//
//// USB接口
// interface USB {
//
//    void openDevice();
//    void closeDevice();
//
//
//
//}



//

//// 键盘类，实现USB接口
// class KeyBoard implements USB {
//    @Override
//    public void openDevice() {
//        System.out.println("打开键盘");
//    }
//    @Override
//    public void closeDevice() {
//        System.out.println("关闭键盘");
//    }
//    public void inPut(){
//        System.out.println("键盘输入");
//    }
//}
//
//
//// 笔记本类：使用USB设备
//class Computer {
//    public void powerOn(){
//        System.out.println("打开笔记本电脑");
//    }
//    public void powerOff(){
//        System.out.println("关闭笔记本电脑");
//    }
//    public void useDevice(USB usb){
//        usb.openDevice();
//        if(usb instanceof Mouse){
//            Mouse mouse = (Mouse)usb;
//            mouse.click();
//        }else if(usb instanceof KeyBoard){
//            KeyBoard keyBoard = (KeyBoard)usb;
//            keyBoard.inPut();
//        }
//        usb.closeDevice();
//    }
//}
//
//
//// 测试类：
// class TestUSB {
//    public static void main(String[] args) {
//        Computer computer = new Computer();
//        computer.powerOn();
//// 使用鼠标设备
//        computer.useDevice(new Mouse());
//// 使用键盘设备
//        computer.useDevice(new KeyBoard());
//        computer.powerOff();
//    }
//}





class Animal {
    protected String name;
    public Animal(String name) {
        this.name = name;
    }
}


class Cat extends Animal implements IRunning {
    public Cat(String name) {
        super(name);
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在用四条腿跑");
    }
}


class Fish extends Animal implements ISwimming {
    public Fish(String name) {
        super(name);
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在用尾巴游泳");
    }
}


class Frog extends Animal implements IRunning, ISwimming {
    public Frog(String name) {
        super(name);
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在往前跳");
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在蹬腿游泳");
    }
}

class Duck extends Animal implements IRunning, ISwimming, IFlying {
    public Duck(String name) {
        super(name);
    }
    @Override
    public void fly() {
        System.out.println(this.name + "正在用翅膀飞");
    }
    @Override
    public void run() {
        System.out.println(this.name + "正在用两条腿跑");
    }
    @Override
    public void swim() {
        System.out.println(this.name + "正在漂在水上");
    }
}


interface IFlying {
    void fly();
}
interface IRunning {
    void run();
}
interface ISwimming {
    void swim();
}

class Robot implements IRunning {
    private String name;

    public Robot(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(this.name + "正在用轮子跑");
    }
}


class Test12 {
    public static void walk(IRunning running) {
        System.out.println("我带着伙伴去散步");
        running.run();
    }

    public static void main(String[] args) {
        Robot robot=new Robot("小飞机");
        walk(robot);
    }
}

